package com.menu;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MenuappActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
	
	private static ProgressBar progbar;
	private Handler handler;
	private boolean isRunning = false;
	private Thread thread;
	private Button btn,btn2;
	private Thread background;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        progbar = (ProgressBar) findViewById(R.id.progbar);
        btn = (Button) findViewById(R.id.btn);
        btn2= (Button) findViewById(R.id.btn2);
        btn.setOnClickListener(this);
        btn.setOnClickListener(this);
        
        handler = new Handler(){
        	
        @Override 
        public void handleMessage(Message msg){
        	progbar.incrementProgressBy(10);
        	}
        };
        
    }
   /* @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	MenuInflater inflate = getMenuInflater();
    	inflate.inflate(R.menu.menu, menu);
		return true;
    	
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem menuitem) {
    	switch(menuitem.getItemId()){
    	case(R.id.item1) :
    		Toast toast = Toast.makeText(getApplicationContext(), "Hello !", Toast.LENGTH_SHORT);
    		toast.show();
    		return true;
    	
    	case (R.id.item2) :
    		Toast toast2 = Toast.makeText(getApplicationContext(), "Hey there !", Toast.LENGTH_SHORT);
    		toast2.show();    		
    		return true;
    	default:	
    	    	return super.onOptionsItemSelected(menuitem);
   	   
    	}   	
    	    	
    		} 	*/
    public void onClick(View v) {
    	progbar = (ProgressBar) findViewById(R.id.progbar);
    	
    		super.onStart();
    		progbar.setProgress(0);
    		background = new Thread(new Runnable() {
    		public void run() {
    			try{
    				for(int i =0;i<10 && isRunning;i++){
    					Thread.sleep(1000);
    					handler.sendMessage(handler.obtainMessage());
    				}
    			}catch(Throwable e){
    				System.out.println(e);
    		}
    		}
    	});
    	
    isRunning = true;
    background.start();
    		  	
    	}
	
	}
			
		   
        
